*Decentralization causes Figure SA5 (model 3)**
*DO FILE TO CREATE MARGINAL EFFECTS GRAPHs*

#delimit ;

mixed raiapproved coalgovtvote_lg subnatcoalvote_lg natcoalXsubnatcoal_lg raiapproved_lg if subtiminginbet_lg==1  || countryno: || regionno: ;

#delimit ;


 
*     ****************************************************************  *;
*              railevel  i.e. x2 = MV                               *;
*     ****************************************************************  *;
generate MV=((_n-1)/10);    

replace MV=. if _n>4000;

matrix b=e(b);
matrix list e(b);
matrix V=e(V);
matrix list e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1];
scalar varb3=V[3,3];
scalar covb1b3=V[1,3];


scalar list b1 b2 b3 varb1 varb3 covb1b3;

gen conb=b1+b3*subnatcoalvote_lg if _n<4000;



*     ****************************************************************  *;
*      These create conditional coefficients for b1      *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*subnatcoalvote_lg^2+2*covb1b3*subnatcoalvote_lg)  if _n<4000;
set more off;
gen cont= conb/conse;


*     ****************************************************************  *;
*      This creates a conditional t                                    *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       Generate confidence intervals at the 95% level                  *;
*     ****************************************************************  *;
*     ****************************************************************  *;

gen a=1.96*conse;
gen upper=conb+a;
gen lower=conb-a;
set textsize 100;


*gen a=1.645*conse;*
*gen upper=conb+a;*
*gen lower=conb-a;*
*set textsize 100;*;

label variable conb "Marginal Effect of National Election Vote Share";
label variable upper "95% CI - upper bound";
label variable lower "95% CI - lower bound";
label variable  subnatcoalvote_lg "Subnational Election Vote Share";



*     ****************************************************************  *;
*       Graph   *;
*                                          *;
*     ****************************************************************  *;
*this gives the full range*;



#delimit ;
gen where=-.0078;
gen pipe = "|";
egen tag_subcoal=tag(subnatcoalvote_lg) if M3obs==1;

#delimit ;

sort subnatcoalvote_lg;

twoway (line conb subnatcoalvote_lg, clpat(solid)) (line upper subnatcoalvote_lg, clpat(shortdash)) (line lower subnatcoalvote_lg, clpat(shortdash)), yline(0) ytitle("Conditional Coefficient of National Election Vote Share") legend(off), scatter where subnatcoalvote_lg if tag_subcoal, plotr(m(b4)) ms(none) mlabcolor(gs5) mlabel (pipe) mlabpos(6);

clear;
